package xml.validations;

public class StructuresValidator {
	public String dataTemp;

	private boolean validate(String data) {
//		if(data == null || data.replaceAll(" ", "").equals(""))
		if(data == null || data.trim().equals(""))
			return true;
		char[] dt = data.toCharArray();

		int parenthesis = 0;
		boolean erro = false;

		for (int i = 0; i < data.length(); i++) {
			String a = String.valueOf(dt[i]);

			if (a.equals("(")) {
				parenthesis++;
			} else if (a.equals(")")) {
				parenthesis--;
			}
			if (parenthesis < 0) {
				erro = true;
				break;
			}

		}
		if (parenthesis != 0) {
			erro = true;
		}

		if (!erro)
			return true;
		else
			return false;

	}

	public boolean isValid(String data) {
		return validate(data);
	}
}